package com.itheima.map;

import java.util.Comparator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class TreeMapDemo01 {
    public static void main(String[] args) {
        TreeMap<Student,String> tm=new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int result=o1.getAge()-o2.getAge();
                result=result==0?o1.getName().compareTo(o2.getName()):result;
                return result;
            }
        });
        Student stu1=new Student("zhangsan",18);
        Student stu2=new Student("lisi",22);
        Student stu3=new Student("wangwu",19);
        tm.put(stu1,"男");
        tm.put(stu2,"女");
        tm.put(stu3,"女");
        tm.forEach((Student key,String value)->{
            System.out.println(key+"--"+value);
        });
        System.out.println("===================");
        Set<Map.Entry<Student, String>> entries = tm.entrySet();
        for (Map.Entry<Student, String> entry : entries) {
            Student key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key+"====="+value);
        }
    }
}
